﻿Imports System.Runtime.Serialization

Namespace WebService

    <DataContract()> _
    Public Class DriverPage
        Inherits PageItem

        Private _plate As String
        Private _color As String
        Private _make As String
        Private _model As String

        <DataMember()> _
        Public Property Plate As String
            Get
                Return _plate
            End Get
            Set(ByVal value As String)
                If value IsNot Nothing Then
                    _plate = value.ToUpper
                End If
            End Set
        End Property

        <DataMember()> _
        Public Property Color As String
            Get
                Return _color
            End Get
            Set(ByVal value As String)
                _color = value
            End Set
        End Property

        <DataMember()> _
        Public Property Make As String
            Get
                Return _make
            End Get
            Set(ByVal value As String)
                _make = value
            End Set
        End Property

        <DataMember()> _
        Public Property Model As String
            Get
                Return _model
            End Get
            Set(ByVal value As String)
                _model = value
            End Set
        End Property

        Protected Overrides Function GetPageTypeName() As String
            Return "Driver"
        End Function

        Protected Overrides Function GetPrimaryValue() As String
            Return Me.Plate
        End Function

        Public Overrides Function Validate() As Boolean
            Return ((Not IsNothing(Me.Plate)) AndAlso (Me.Plate.Length > 0))
        End Function

        Protected Overrides Function CopyFrom(ByVal page As PageItem) As Boolean
            Dim rv As Boolean = False

            If (TypeOf page Is DriverPage) Then
                rv = True
                Dim p = CType(page, DriverPage)
                If (hasValue(p.Color)) Then
                    Me.Color = p.Color
                End If
                If (hasValue(p.Make)) Then
                    Me.Make = p.Make
                End If
                If (hasValue(p.Model)) Then
                    Me.Model = p.Model
                End If
            End If

            Return rv

        End Function

        Public Overrides Function UserPropertiesMatch(ByVal other As PageItem) As Boolean
            Dim rv = False
            If (other IsNot Nothing AndAlso TypeOf other Is DriverPage) Then
                Dim dp = CType(other, DriverPage)
                rv = (MyBase.UserPropertiesMatch(other) AndAlso
                      Me.Color = dp.Color AndAlso
                      Me.Make = dp.Make AndAlso
                      Me.Model = dp.Model AndAlso
                      Me.Plate = dp.Plate)
            End If
            Return rv
        End Function

    End Class

End Namespace
